﻿using Cips.DataMining;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Cips.DataMining.Tests
{
    using Item = Tuple<bool, bool, double>;

    /// <summary>
    /// This is a test class for TermMatrixTest and is intended
    /// to contain all TermMatrixTest Unit Tests
    ///</summary>
    [TestClass]
    public class TermMatrixTest
    {
        [TestMethod]
        public void TestFullMultiply()
        {
            var dictionary = new TermDictionary<bool>();
            var a = new TermMatrix<bool>(dictionary, new[] { new Item(false, false, 1), new Item(true, true, 0.5) });
            var b = new TermMatrix<bool>(dictionary, new[] { new Item(true, false, 1), new Item(false, true, 0.5), new Item(true, true, 0.3) });
            var x = a * b;

            Assert.AreEqual(0, x[false][false]);
            Assert.AreEqual(0.5, x[false][true]);
            Assert.AreEqual(0.5, x[true][false]);
            Assert.AreEqual(0.15, x[true][true]);
        }

        [TestMethod]
        public void TestNormalize()
        {
            var dictionary = new TermDictionary<bool>();
            
            var a = new TermMatrix<bool>(dictionary, new[] { new Item(false, false, 1), new Item(true, true, 0.5) });
            var x = a.MarkovNormalize();

            Assert.AreEqual(1, x[false][false]);
            Assert.AreEqual(0, x[false][true]);
            Assert.AreEqual(0, x[true][false]);
            Assert.AreEqual(1, x[true][true]);
        }

        [TestMethod]
        public void TestTranspose()
        {
            var dictionary = new TermDictionary<bool>();

            var a = new TermMatrix<bool>(dictionary, new[] { new Item(false, true, 1), new Item(true, true, 0.5) });
            var x = a.Transpose();

            Assert.AreEqual(0, x[false][false]);
            Assert.AreEqual(0, x[false][true]);
            Assert.AreEqual(1, x[true][false]);
            Assert.AreEqual(0.5, x[true][true]);
        }
    }
}
